package com.abc.robot01.fragment

import android.os.Bundle
import android.util.Log
import androidx.core.content.ContextCompat
import androidx.preference.ListPreference
import androidx.preference.PreferenceFragmentCompat
import androidx.preference.PreferenceScreen
import com.abc.robot01.R

/**
 *
 */
class SettingsFragment : PreferenceFragmentCompat() {
    val TAG="SettingsFragment"
    override fun onCreatePreferences(savedInstanceState: Bundle?, rootKey: String?) {
        setPreferencesFromResource(R.xml.preferences, rootKey)
        val syncPreference = findPreference<ListPreference>("sync_frequency")
        syncPreference?.setOnPreferenceChangeListener { preference, newValue ->
        Log.e(TAG,"newValue:$newValue");
        true
        }
    }

    override fun onNavigateToScreen(preferenceScreen: PreferenceScreen) {
        super.onNavigateToScreen(preferenceScreen)
        Log.e(TAG,"onNavigateToScreen:${preferenceScreen.key}");

        val fragment = SettingsFragment()
        val args = Bundle()
        args.putString(PreferenceFragmentCompat.ARG_PREFERENCE_ROOT, preferenceScreen.key)
        fragment.arguments = args

        parentFragmentManager.beginTransaction()
            .replace(R.id.fragment_container, fragment)
            .addToBackStack(null)
            .commit()
    }

}